package cnpm.dao.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import cnpm.dao.BankDAO;
import cnpm.entity.Bank;
import cnpm.util.HibernateUtil;

public class BankDAOImpl implements BankDAO{

	private SessionFactory sessionFactory;
	private Session session;
	
	public BankDAOImpl() {
		sessionFactory = HibernateUtil.getSessionFactory();
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Bank> getALlBank() {
		List<Bank> list=null;
		try{
			session = sessionFactory.openSession();
			list = (List<Bank>) session.createCriteria(Bank.class).list();
		}catch(HibernateException e){
			e.printStackTrace();
		}finally{
			session.close();
		}
		return list;
	}

	@Override
	public Bank getBankByID(int bankID) {
		Bank bank = null;
		try{
			session = sessionFactory.openSession();
			bank = (Bank) session.get(Bank.class, bankID);
			return bank;
		}catch(HibernateException e1){
			e1.printStackTrace();
		}finally{
			session.close();
		}
		return bank;
	}

}
